package com.dykj.fireFighting.server.fire.maintenanceplan.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dykj.fireFighting.api.fire.maintenanceplan.dto.RoutineMaintenanceDto;
import com.dykj.fireFighting.api.fire.maintenanceplan.entity.RoutineMaintenance;
import com.dykj.fireFighting.api.fire.maintenanceplan.service.IRoutineMaintenanceService;
import com.dykj.fireFighting.api.fire.maintenanceplan.vo.RoutineMaintenanceNumVo;
import com.dykj.fireFighting.api.fire.maintenanceplan.vo.RoutineMaintenanceVo;
import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.server.fire.maintenanceplan.mapper.RoutineMaintenanceMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 例行维保记录
 *
 * @Author zly
 * @Date 2021-07-28 16:30:03
 */
@Slf4j
@DubboService
@Transactional(rollbackFor = Exception.class)
public class RoutineMaintenanceServiceImpl extends BaseServiceImpl<RoutineMaintenanceMapper, RoutineMaintenance> implements IRoutineMaintenanceService {


    @Override
    public PageVo<RoutineMaintenanceVo> queryList(RoutineMaintenanceDto routineMaintenanceDto) {
        HashMap<String, Object> params = new HashMap<>(16);

        params.put("maintenanceDept", routineMaintenanceDto.getMaintenanceDept());
        params.put("sociologyDept", routineMaintenanceDto.getSociologyDept());
        params.put("beginTime", routineMaintenanceDto.getBeginTime());
        params.put("endTime", routineMaintenanceDto.getEndTime());
        Page page = new Page();
        // 设置当前页码
        page.setCurrent(routineMaintenanceDto.getPage());
        // 设置页大小
        page.setSize(routineMaintenanceDto.getLimit());

        return new PageVo<RoutineMaintenanceVo>(this.baseMapper.queryList(page, params));
    }

    @Override
    public List<RoutineMaintenanceNumVo> getNumStatistic(String wbId) {
        return this.baseMapper.getNumStatistic(wbId);
    }

    /**
     * 根据不同条件获取维保数量
     *
     * @param params wbId：维保单位id，type：year-查询本年,month-查询本月,week-查询本周
     * @return
     */
    @Override
    public int getMaintenanceNum(Map<String, String> params) {
        return this.baseMapper.getMaintenanceNum(params);
    }

    @Override
    public RoutineMaintenance getRoutineMaintenanceMessage(String id) {
        return this.baseMapper.getRoutineMaintenanceMessage(id);
    }

    @Override
    public List<RoutineMaintenanceVo> queryRoutineMaintenanceEvaluationInfoList(RoutineMaintenanceDto routineMaintenanceDto) {
        Map<String, Object> params = new HashMap<>();
        params.put("maintenanceDeptId", routineMaintenanceDto.getMaintenanceDept());
        params.put("evaluationDate", routineMaintenanceDto.getEvaluationDate());
        return this.baseMapper.queryRoutineMaintenanceEvaluationInfoList(params);
    }
}
